//
//  HomeViewController.m
//  BestPurchase
//
//  Created by ZSMAC on 2018/10/9.
//  Copyright © 2018年 张帅. All rights reserved.
//

#import "HomeViewController.h"
#import "CKSlideMenu.h"
#import "DepartmentView.h"
@interface HomeViewController ()

@end

@implementation HomeViewController
- (void)viewWillAppear:(BOOL)animated {
    if (!self.navigationController.navigationBarHidden) {
        self.navigationController.navigationBarHidden=YES;
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor= MyRGB(239, 239, 239);
    [self UIconfigur];
}
- (void)UIconfigur {
    [self addTopBar];
    
    NSArray *titles = @[@"百货",@"女装",@"男装",@"鞋包",@"电器",@"家装",@"其他",];
    NSMutableArray *arr = [NSMutableArray array];
    for (int i = 0; i <titles.count ; i++) {
        CGFloat height = SCREEN_HEIGHT- 54-NavBarHeight-50;
        DepartmentView * view = [[DepartmentView alloc] initWithFrame:CGRectMake(0, 30, SCREEN_WIDTH, height)];
        view.goodsType=titles[i];
        [arr addObject:view];
    }
    CKSlideMenu *slideMenu = [[CKSlideMenu alloc]initWithFrame:CGRectMake(0, NavBarHeight, self.view.frame.size.width, 40) titles:titles controllers:arr];
    
    slideMenu.bodyFrame = CGRectMake(0,  NavBarHeight + 54, SCREEN_WIDTH, SCREEN_HEIGHT - 54 - NavBarHeight);
    slideMenu.backgroundColor=[UIColor clearColor];
    slideMenu.unselectedColor=[UIColor whiteColor];
    slideMenu.selectedColor=[UIColor whiteColor];
    slideMenu.indicatorColor=[UIColor whiteColor];
    slideMenu.font=[UIFont boldSystemFontOfSize:17];
    slideMenu.showLine=NO;
    [slideMenu scrollToIndex:0];
    @WeakObj(arr);
    [slideMenu setTurnPageBlock:^(NSInteger currentPage) {
      DepartmentView * view= arrWeak[currentPage];
        [view refreshDataExternalRefresh:YES];
    }];
    
    [slideMenu setClickTitleBlock:^(NSInteger currentPage) {
        DepartmentView * view= arrWeak[currentPage];
        [view refreshDataExternalRefresh:YES];
    }];
    
    DepartmentView * view= arr.firstObject;
    [view refreshDataExternalRefresh:YES];
    [self.view addSubview:slideMenu];
    
}
- (void)addTopBar {
    
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 200)];
    imageView.backgroundColor=[UIColor colorWithRed: arc4random_uniform(256)/255.0f green: arc4random_uniform(256)/255.0f blue: arc4random_uniform(256)/255.0f alpha:1];
    imageView.image=[UIImage imageNamed:@"beijing2.jpg"];
    [self.view addSubview:imageView];
    UIToolbar *bar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, imageView.height)];
    bar.barStyle = UIBarStyleBlack;
    bar.alpha = 0.5;
    [self.view addSubview:bar];
    
    UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, StatusBar_Rect.size.height+10, 80, 25)];
    titleLabel.font=[UIFont boldSystemFontOfSize:20];
    titleLabel.text=@"优购";
    titleLabel.textColor=[UIColor whiteColor];
    [self.view addSubview:titleLabel];
    
    
    UIImageView * serchImageView = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-35, StatusBar_Rect.size.height+10, 20, 20)];
    serchImageView.image=[UIImage imageNamed:@"搜索.png"];
    [self.view addSubview:serchImageView];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
